package Stack;

import java.util.ArrayList;
import java.util.List;

public class _456_132Pattern {
    //hint:be careful of the same value:[1,2,3,2]
    public boolean find132pattern(int[] nums) {
        int s = 0;
        List<int[]> interval = new ArrayList<>();
        for (int i = 1; i < nums.length; i++) {
            if (nums[i-1] <= nums[i]) {
                if (s < i - 1) {
                    interval.add(new int[]{nums[s], nums[i]});
                } else {
                    interval.add(new int[]{nums[i-1], nums[i]});
                }
            } else {
                s = i;
            }
            for (int[] temp : interval) {
                if (nums[i] > temp[0] && nums[i] < temp[1]) {
                    return true;
                }
            }
        }
        return false;
    }
}
